<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/views/dashboard/mixins/resize.js'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart: null,
      scatterData:{}
    }
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions() {
      this.chart.setOption({
    xAxis: {
      type: 'category',
      data: this.scatterData.xAxis
    },
    yAxis: {},
    series: [{
        symbolSize: 20,
        data: [
            ['2016-1', '8.04'],
            ['2016-2', '6.95'],
            ['2016-3', '7.58'],
            ['2016-4', '8.81'],
            ['2016-5', '8.33'],
            ['2016-6', '9.96'],
            ['2016-7', '7.24'],
            ['2016-8', '4.26'],
            ['2016-9', '10.84'],
            ['2016-10', '4.82'],
            ['2016-11', '5.68']
            ['2016-12', '5.68']
        ],
        type: 'scatter'
    },
    {
        symbolSize: 20,
        data: [
            ['2016-1', '1'],
            ['2016-2', '2'],
            ['2016-3', '3'],
            ['2016-4', 8.81],
            ['2016-5', 8.33],
            ['2016-6', 9.96],
            ['2016-7', 7.24],
            ['2016-8', 4.26],
            ['2016-9', 10.84],
            ['2016-10', 4.82],
            ['2016-11', 5.68]
            ['2016-12', 5.68]
        ],
        type: 'scatter'
    }]
})
    }
  }
}
// {
//     xAxis: {
//             type: 'category',
//             axisTick: {
//                 alignWithLabel: true
//             },
//             axisLine: {
//                 onZero: false,
//                 lineStyle: {
//                     color: colors[1]
//                 }
//             },

//             data: ['2016-1', '2016-2', '2016-3', '2016-4', '2016-5', '2016-6', '2016-7', '2016-8', '2016-9', '2016-10', '2016-11', '2016-12']
//     },
//     yAxis: {},
//     series: [{
//         symbolSize: 20,
//         data: [
//             ['2016-1', 8.04],
//             ['2016-2', 6.95],
//             ['2016-3', 7.58],
//             ['2016-4', 8.81],
//             ['2016-5', 8.33],
//             ['2016-6', 9.96],
//             ['2016-7', 7.24],
//             ['2016-8', 4.26],
//             ['2016-9', 10.84],
//             ['2016-10', 4.82],
//             ['2016-11', 5.68]
//         ],
//         type: 'scatter'
//     }]
// }
</script>
